package org.example.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author linjinde
 */
public class ReadPropertiesUtil {
    public static MyProperties readProperties(String filePath) {
        MyProperties properties = new MyProperties();
        InputStream inputStream = ReadPropertiesUtil.class.getResourceAsStream(filePath);
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

    public static Map<String, String> getAttrMapping(MyProperties properties) {

        Map<String, String> map = new HashMap<>();
        Set<String> stringPropertyNames = properties.stringPropertyNames();
        String[] array = stringPropertyNames.toArray(new String[0]);
        for (int i = array.length - 1; i >= 0; i--) {
            String value = (String) properties.get(array[i]);
            map.put(array[i], value);
        }
        return map;
    }

}
